export function onRouteChange({ matchedRoutes }) {
  if (matchedRoutes.length) {
    
  }
}
import { history } from 'umi';
import request from '@/utils/request';

export function render(oldRender: any) {
  request
    .get('/user/self')
    .then((res) => {
      const { user } = res.data;
      if (user && user.id) {
        localStorage.setItem('uid', user.id);
        localStorage.setItem('userinfo', JSON.stringify(user));
        if (history.location.pathname === '/login') {
          history.replace('/');
        }
        oldRender();
      } else {
        history.replace('/login');
        oldRender();
      }
    })
    .catch((err) => {
      console.log('err', err);
      history.replace('/login');
      oldRender();
    });
}
